#ifndef PLAYER_H
#define PLAYER_H

#include <list>
#include <time.h>
#include <iostream>
#include <event.h>	//包含了libevent的event2的所有头文件，除了event2/listener.h 
#include <jsoncpp/json/json.h>

class Server;

struct PlayerInfo
{
	std::string deviceid;
	std::string appid;
	std::string cur_music;
	int volume;
	int mode;
	time_t d_time;					//记录音箱上报的时间
	time_t a_time;					//记录APP上报的时间
	
	struct bufferevent *d_bev;		//对应音箱事件
	struct bufferevent *a_bev;		//对应APP事件
};

class Player
{
private:
	std::list<PlayerInfo> *info;	//链表对象	
public:
	Player();
	~Player();
	
	//通过&引用传递可以避免复制整个 Json::Value 对象，特别是当 std::string 较大时，这可以显著提高性能。
	void player_update_list(struct bufferevent *, Json::Value &, Server *);
	void player_app_update_list(struct bufferevent *, Json::Value &);
	void player_traverse_list();
	void debug(const char *);
	void player_upload_music(Server *, struct bufferevent *, Json::Value &);
	
	void palyer_option(Server *, struct bufferevent *, Json::Value &);
	void palyer_reply_option(Server *, struct bufferevent *, Json::Value &);
	void player_offline(struct bufferevent *);
	void player_app_offline(struct bufferevent *);
	void player_get_music(Server *, struct bufferevent *, Json::Value &);
};

#endif
